| 1 | create table AppUser
|
|---|
| 2 | (
|
|---|
| 3 | id serial primary key,
|
|---|
| 4 | first_name varchar(20) not null check ( char_length(first_name) >= 1 ) default 'UNKNOWN',
|
|---|
| 5 | last_name varchar(20) not null check ( char_length(last_name) >= 1 ) default 'USER',
|
|---|
| 6 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' ),
|
|---|
| 7 | username varchar(30) not null unique,
|
|---|
| 8 | password_hash text not null check (char_length(password_hash) >= 8),
|
|---|
| 9 | date_of_birth date not null check ( date_of_birth >= date '1900-01-01' and date_of_birth <= current_date),
|
|---|
| 10 | phone_number varchar(15) not null check (phone_number ~ '^\+?[0-9]{7,15}$')
|
|---|
| 11 | );
|
|---|
| 12 |
|
|---|
| 13 | create table Dispatcher
|
|---|
| 14 | (
|
|---|
| 15 | user_id int4 primary key references AppUser (id) on update cascade on delete restrict
|
|---|
| 16 | );
|
|---|
| 17 |
|
|---|
| 18 | create table Admin
|
|---|
| 19 | (
|
|---|
| 20 | user_id int4 primary key references AppUser (id) on update cascade on delete restrict
|
|---|
| 21 | );
|
|---|
| 22 |
|
|---|
| 23 | create table DriverLicense
|
|---|
| 24 | (
|
|---|
| 25 | id serial primary key,
|
|---|
| 26 | issue_date date not null check (issue_date >= DATE '1900-01-01' and issue_date <= CURRENT_DATE),
|
|---|
| 27 | expire_date date not null,
|
|---|
| 28 | license_id varchar(20) not null,
|
|---|
| 29 | check ( expire_date > issue_date )
|
|---|
| 30 | );
|
|---|
| 31 |
|
|---|
| 32 | create table DriverLicenseCategory
|
|---|
| 33 | (
|
|---|
| 34 | id serial primary key,
|
|---|
| 35 | category_name varchar(5) not null unique
|
|---|
| 36 | );
|
|---|
| 37 |
|
|---|
| 38 | insert into DriverLicenseCategory (category_name)
|
|---|
| 39 | values ('AM'),
|
|---|
| 40 | ('A1'),
|
|---|
| 41 | ('A2'),
|
|---|
| 42 | ('A'),
|
|---|
| 43 | ('B'),
|
|---|
| 44 | ('C1'),
|
|---|
| 45 | ('C'),
|
|---|
| 46 | ('D1'),
|
|---|
| 47 | ('D'),
|
|---|
| 48 | ('BE'),
|
|---|
| 49 | ('C1E'),
|
|---|
| 50 | ('CE'),
|
|---|
| 51 | ('D1E'),
|
|---|
| 52 | ('DE'),
|
|---|
| 53 | ('F'),
|
|---|
| 54 | ('G'),
|
|---|
| 55 | ('T');
|
|---|
| 56 |
|
|---|
| 57 | create table Driver
|
|---|
| 58 | (
|
|---|
| 59 | user_id int4 primary key references AppUser (id) on update cascade on delete restrict,
|
|---|
| 60 | driver_license_id int4 not null references DriverLicense (id) on update cascade on delete restrict,
|
|---|
| 61 | latitude double precision check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 62 | longitude double precision check ( longitude >= -180 and longitude <= 180 )
|
|---|
| 63 | );
|
|---|
| 64 |
|
|---|
| 65 | create table DriverLicense_DriverLicenseCategory
|
|---|
| 66 | (
|
|---|
| 67 | driver_license_id int4 references DriverLicense (id) on update cascade on delete restrict,
|
|---|
| 68 | driver_license_category_id int4 references DriverLicenseCategory (id) on update cascade on delete restrict,
|
|---|
| 69 | primary key (driver_license_id, driver_license_category_id)
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | create table FreelanceDriver
|
|---|
| 73 | (
|
|---|
| 74 | driver_user_id integer not null primary key references driver on update cascade on delete restrict,
|
|---|
| 75 | pricing_info_id int4 not null references pricinginfo (id),
|
|---|
| 76 | area_id int4 not null references area (id)
|
|---|
| 77 | );
|
|---|
| 78 |
|
|---|
| 79 | create table Company
|
|---|
| 80 | (
|
|---|
| 81 | id serial primary key,
|
|---|
| 82 | name varchar(50) not null check ( char_length(name) >= 1 and name ~ '^[A-Za-z0-9 &''.-]+$'),
|
|---|
| 83 | date_founded date not null check ( date_founded <= current_date and date_founded >= date '1800-01-01' ),
|
|---|
| 84 | tax_number varchar(20) not null check ( tax_number ~ '^[A-Z0-9]{5,20}$' ),
|
|---|
| 85 | phone_number varchar(15) not null check ( phone_number ~ '^\+?[0-9]{7,15}$' ),
|
|---|
| 86 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' ),
|
|---|
| 87 | website varchar(255) CHECK ( website is null or website ~* '^(https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}(\/.*)?$'),
|
|---|
| 88 | active bool not null default true
|
|---|
| 89 | );
|
|---|
| 90 |
|
|---|
| 91 | create table EmploymentHistory
|
|---|
| 92 | (
|
|---|
| 93 | employee_user_id int4 not null references AppUser (id) on update cascade on delete cascade,
|
|---|
| 94 | start_date date not null check ( start_date <= current_date ),
|
|---|
| 95 | end_date date,
|
|---|
| 96 | company_id int4 not null references Company (id) on update cascade on delete restrict,
|
|---|
| 97 | primary key (employee_user_id,
|
|---|
| 98 | start_date,
|
|---|
| 99 | company_id),
|
|---|
| 100 | check (end_date is null or (end_date > start_date and end_date <= current_date))
|
|---|
| 101 | );
|
|---|
| 102 |
|
|---|
| 103 | create table Area
|
|---|
| 104 | (
|
|---|
| 105 | id serial primary key,
|
|---|
| 106 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 107 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 108 | radius decimal not null check ( radius > 0 and radius <= 100000), -- in meters, max is 100km
|
|---|
| 109 | name varchar(100) not null check ( (char_length(trim(name)) >= 2) )
|
|---|
| 110 | );
|
|---|
| 111 |
|
|---|
| 112 | create table CurrencyCatalog
|
|---|
| 113 | (
|
|---|
| 114 | id serial primary key,
|
|---|
| 115 | currency varchar(5) not null unique
|
|---|
| 116 | );
|
|---|
| 117 | insert into CurrencyCatalog (currency)
|
|---|
| 118 | values ('USD'), -- US Dollar
|
|---|
| 119 | ('EUR'), -- Euro
|
|---|
| 120 | ('GBP'), -- British Pound
|
|---|
| 121 | ('MKD'), -- Macedonian Denar
|
|---|
| 122 | ('CHF'), -- Swiss Franc
|
|---|
| 123 | ('JPY'), -- Japanese Yen
|
|---|
| 124 | ('CNY'), -- Chinese Yuan
|
|---|
| 125 | ('AUD'), -- Australian Dollar
|
|---|
| 126 | ('CAD'), -- Canadian Dollar
|
|---|
| 127 | ('NZD'), -- New Zealand Dollar
|
|---|
| 128 | ('SEK'), -- Swedish Krona
|
|---|
| 129 | ('NOK'), -- Norwegian Krone
|
|---|
| 130 | ('DKK'), -- Danish Krone
|
|---|
| 131 | ('RSD'), -- Serbian Dinar
|
|---|
| 132 | ('BGN'), -- Bulgarian Lev
|
|---|
| 133 | ('TRY'), -- Turkish Lira
|
|---|
| 134 | ('INR'), -- Indian Rupee
|
|---|
| 135 | ('BRL'), -- Brazilian Real
|
|---|
| 136 | ('ZAR'), -- South African Rand
|
|---|
| 137 | ('SGD'), -- Singapore Dollar
|
|---|
| 138 | ('HKD'), -- Hong Kong Dollar
|
|---|
| 139 | ('KRW'), -- South Korean Won
|
|---|
| 140 | ('MXN'), -- Mexican Peso
|
|---|
| 141 | ('PLN'), -- Polish Zloty
|
|---|
| 142 | ('CZK'), -- Czech Koruna
|
|---|
| 143 | ('HUF'), -- Hungarian Forint
|
|---|
| 144 | ('ILS'), -- Israeli Shekel
|
|---|
| 145 | ('AED'), -- UAE Dirham
|
|---|
| 146 | ('SAR'), -- Saudi Riyal
|
|---|
| 147 | ('THB'); -- Thai Baht
|
|---|
| 148 |
|
|---|
| 149 | create type unit_type as enum ('kilometer', 'minute');
|
|---|
| 150 | create table PricingInfo
|
|---|
| 151 | (
|
|---|
| 152 | id serial primary key,
|
|---|
| 153 | value numeric(19, 2) not null check ( value > 0 ),
|
|---|
| 154 | unit unit_type not null,
|
|---|
| 155 | currency_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict
|
|---|
| 156 | );
|
|---|
| 157 |
|
|---|
| 158 | create table Company_Area
|
|---|
| 159 | (
|
|---|
| 160 | company_id int4 not null references Company (id) on update cascade on delete cascade,
|
|---|
| 161 | area_id int4 not null references Area (id) on update cascade on delete cascade,
|
|---|
| 162 | pricing_info_id int4 not null references PricingInfo (id) on update cascade on delete restrict,
|
|---|
| 163 | primary key (company_id, area_id)
|
|---|
| 164 | );
|
|---|
| 165 |
|
|---|
| 166 | create table Brand
|
|---|
| 167 | (
|
|---|
| 168 | id serial primary key,
|
|---|
| 169 | name varchar(50) not null check ( char_length(name) >= 1 and name ~ '^[A-Za-z0-9 &''.-]+$'),
|
|---|
| 170 | date_founded date not null check ( date_founded <= current_date and date_founded >= date '1800-01-01' ),
|
|---|
| 171 | phone_number varchar(15) check ( phone_number is null or phone_number ~ '^\+?[0-9]{7,15}$' ),
|
|---|
| 172 | email varchar(254) check ( email is null or email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' )
|
|---|
| 173 | );
|
|---|
| 174 |
|
|---|
| 175 | create table ModelFuelTypeCatalog
|
|---|
| 176 | (
|
|---|
| 177 | id serial primary key,
|
|---|
| 178 | type varchar(20) not null unique check (char_length(trim(type)) > 1)
|
|---|
| 179 | );
|
|---|
| 180 | insert into ModelFuelTypeCatalog (type)
|
|---|
| 181 | values ('Petrol'),
|
|---|
| 182 | ('Diesel'),
|
|---|
| 183 | ('Electric'),
|
|---|
| 184 | ('Hybrid'),
|
|---|
| 185 | ('Plug-in Hybrid'),
|
|---|
| 186 | ('Hydrogen');
|
|---|
| 187 | create table ModelTransmissionCatalog
|
|---|
| 188 | (
|
|---|
| 189 | id serial primary key,
|
|---|
| 190 | transmission varchar(20) not null unique check (char_length(trim(transmission)) > 1)
|
|---|
| 191 | );
|
|---|
| 192 | insert into ModelTransmissionCatalog (transmission)
|
|---|
| 193 | values ('Automatic'),
|
|---|
| 194 | ('Manual');
|
|---|
| 195 |
|
|---|
| 196 | create table Model
|
|---|
| 197 | (
|
|---|
| 198 | id serial primary key,
|
|---|
| 199 | name varchar(50) not null check (char_length(trim(name)) >= 2),
|
|---|
| 200 | engine_capacity_cc decimal check (engine_capacity_cc > 0),
|
|---|
| 201 | body_style varchar(50) check (body_style is null or char_length(trim(body_style)) >= 2),
|
|---|
| 202 | brand_id int4 not null references Brand (id) on update cascade on delete restrict,
|
|---|
| 203 | model_fuel_type_catalog_id int4 not null references ModelFuelTypeCatalog (id) on update cascade on delete restrict,
|
|---|
| 204 | model_transmission_catalog_id int4 not null references ModelTransmissionCatalog (id) on update cascade on delete restrict
|
|---|
| 205 | );
|
|---|
| 206 |
|
|---|
| 207 | create table Vehicle
|
|---|
| 208 | (
|
|---|
| 209 | VIN varchar(17) primary key,
|
|---|
| 210 | passenger_capacity int4 not null check (passenger_capacity > 0 and passenger_capacity <= 50) default 1,
|
|---|
| 211 | year int4 not null check (year > 1950 and year <= extract(year from current_date)),
|
|---|
| 212 | wheelchair_accessible bool not null default false,
|
|---|
| 213 | model_id int4 not null references Model (id) on update cascade on delete restrict,
|
|---|
| 214 | category_id int4 not null references DriverLicenseCategory (id) on update cascade on delete restrict
|
|---|
| 215 | );
|
|---|
| 216 |
|
|---|
| 217 | create table ServiceHistory
|
|---|
| 218 | (
|
|---|
| 219 | id serial primary key,
|
|---|
| 220 | date date not null check ( date <= current_date ),
|
|---|
| 221 | price numeric(19, 2) not null check ( price > 0 ),
|
|---|
| 222 | currency_catalog_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 223 | fault_description text,
|
|---|
| 224 | fix_description text,
|
|---|
| 225 | vehicle_VIN varchar(17) references Vehicle (VIN) on update cascade on delete restrict
|
|---|
| 226 | );
|
|---|
| 227 |
|
|---|
| 228 | create table VehicleOwnership
|
|---|
| 229 | (
|
|---|
| 230 | vehicle_VIN varchar(17) not null references Vehicle (VIN) on update cascade on delete restrict,
|
|---|
| 231 | company_id int4 references Company (id) on update cascade on delete set null,
|
|---|
| 232 | freelance_driver_user_id int4 references FreelanceDriver (driver_user_id) on update cascade on delete set null,
|
|---|
| 233 | from_date date not null check ( from_date <= current_date ),
|
|---|
| 234 | to_date date,
|
|---|
| 235 | license_plate varchar(20) check ( license_plate is null or license_plate ~ '^[A-Z0-9-]{1,20}$' ),
|
|---|
| 236 | primary key (vehicle_VIN, from_date),
|
|---|
| 237 | check (to_date is null or to_date > from_date)
|
|---|
| 238 | );
|
|---|
| 239 |
|
|---|
| 240 | create table Registration
|
|---|
| 241 | (
|
|---|
| 242 | id serial primary key,
|
|---|
| 243 | vehicle_VIN varchar(17) not null,
|
|---|
| 244 | registration_date date not null check ( registration_date < current_date ),
|
|---|
| 245 | expiration_date date,
|
|---|
| 246 | vehicle_ownership_from_date date not null,
|
|---|
| 247 | check ( expiration_date is null or expiration_date > registration_date ),
|
|---|
| 248 | foreign key (vehicle_VIN, vehicle_ownership_from_date) references VehicleOwnership (vehicle_VIN, from_date) on update cascade on delete restrict,
|
|---|
| 249 | foreign key (vehicle_VIN) references Vehicle (VIN) on update cascade on delete restrict
|
|---|
| 250 | );
|
|---|
| 251 |
|
|---|
| 252 | create table Customer
|
|---|
| 253 | (
|
|---|
| 254 | user_id int4 primary key references AppUser (id) on update cascade on delete restrict
|
|---|
| 255 | );
|
|---|
| 256 |
|
|---|
| 257 | create table CustomerPreference
|
|---|
| 258 | (
|
|---|
| 259 | id serial primary key,
|
|---|
| 260 | seqno int4 not null check ( seqno > 0 ),
|
|---|
| 261 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete restrict,
|
|---|
| 262 | freelance_driver_user_id int4 references FreelanceDriver (driver_user_id) on update cascade on delete set null,
|
|---|
| 263 | company_id int4 references Company (id) on update cascade on delete set null,
|
|---|
| 264 | check (
|
|---|
| 265 | (freelance_driver_user_id is not null and company_id is null)
|
|---|
| 266 | or
|
|---|
| 267 | (freelance_driver_user_id is null and company_id is not null)
|
|---|
| 268 | ),
|
|---|
| 269 | unique (customer_user_id, seqno)
|
|---|
| 270 | );
|
|---|
| 271 |
|
|---|
| 272 | create type request_status as enum ('pending', 'accepted', 'in_progress', 'completed', 'cancelled');
|
|---|
| 273 | create table Request
|
|---|
| 274 | (
|
|---|
| 275 | id serial primary key,
|
|---|
| 276 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete restrict,
|
|---|
| 277 | start_latitude double precision not null check ( start_latitude >= -90 and start_latitude <= 90 ),
|
|---|
| 278 | start_longitude double precision not null check ( start_longitude >= -180 and start_longitude <= 180 ),
|
|---|
| 279 | end_latitude double precision not null check ( end_latitude >= -90 and end_latitude <= 90 ),
|
|---|
| 280 | end_longitude double precision not null check ( end_longitude >= -180 and end_longitude <= 180 ),
|
|---|
| 281 | timestamp timestamp not null default current_timestamp,
|
|---|
| 282 | number_of_adult_passengers int4 not null default 1 check (number_of_adult_passengers >= 1),
|
|---|
| 283 | number_of_children int4 default 0 check (number_of_children >= 0),
|
|---|
| 284 | status request_status not null default 'pending',
|
|---|
| 285 | female_driver bool not null default false,
|
|---|
| 286 | luggage bool not null default false,
|
|---|
| 287 | luggage_count int4 not null default 0 check ( luggage_count >= 0 ),
|
|---|
| 288 | baby_seat_count int4 not null default 0 check ( baby_seat_count >= 0 )
|
|---|
| 289 | );
|
|---|
| 290 |
|
|---|
| 291 | create table Waypoints
|
|---|
| 292 | (
|
|---|
| 293 | id serial primary key,
|
|---|
| 294 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 295 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 296 | seqno int4 not null check ( seqno > 0 ),
|
|---|
| 297 | request_id int4 references Request (id) on update cascade on delete cascade,
|
|---|
| 298 | unique (request_id, seqno)
|
|---|
| 299 | );
|
|---|
| 300 |
|
|---|
| 301 | create type offer_status as enum ('pending', 'accepted', 'rejected', 'cancelled', 'completed');
|
|---|
| 302 | create table Offer
|
|---|
| 303 | (
|
|---|
| 304 | id serial primary key,
|
|---|
| 305 | status offer_status NOT NULL default 'pending',
|
|---|
| 306 | created_at timestamp not null default current_timestamp,
|
|---|
| 307 | request_id int4 not null references Request (id) on update cascade on delete restrict,
|
|---|
| 308 | dispatcher_user_id int4 references Dispatcher (user_id) on update cascade on delete set null,
|
|---|
| 309 | driver_user_id int4 references Driver (user_id) on update cascade on delete set null,
|
|---|
| 310 | price numeric(19, 2) not null check ( price > 0 ) default 1,
|
|---|
| 311 | currency_catalog_id int4 references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 312 | ETA timestamp,
|
|---|
| 313 | customer_user_id int4 references Customer (user_id) on update cascade on delete set null,
|
|---|
| 314 | check ( driver_user_id <> dispatcher_user_id )
|
|---|
| 315 | );
|
|---|
| 316 |
|
|---|
| 317 | create type ride_status as enum ('scheduled', 'in_progress', 'completed', 'cancelled');
|
|---|
| 318 | create table Ride
|
|---|
| 319 | (
|
|---|
| 320 | id serial primary key,
|
|---|
| 321 | start_time timestamp not null default current_timestamp,
|
|---|
| 322 | end_time timestamp,
|
|---|
| 323 | distance_traveled numeric(10, 2) not null default 0 check ( distance_traveled >= 0 ),
|
|---|
| 324 | vehicle_VIN varchar(17) not null references Vehicle (VIN) on update cascade on delete restrict,
|
|---|
| 325 | driver_user_id int4 not null references Driver (user_id) on update cascade on delete restrict,
|
|---|
| 326 | request_id int4 not null references Request (id) on update cascade on delete restrict,
|
|---|
| 327 | status ride_status not null default 'scheduled',
|
|---|
| 328 | offer_id int4 not null references Offer (id) on update cascade on delete restrict,
|
|---|
| 329 | check ( end_time is null or end_time > start_time )
|
|---|
| 330 | );
|
|---|
| 331 |
|
|---|
| 332 | create table Review
|
|---|
| 333 | (
|
|---|
| 334 | id serial primary key,
|
|---|
| 335 | rating numeric(3, 2) not null default 0 check ( rating >= 0 and rating <= 5 ),
|
|---|
| 336 | comment text check ( char_length(comment) <= 1000 ),
|
|---|
| 337 | ride_id int4 not null references Ride (id) on update cascade on delete restrict,
|
|---|
| 338 | customer_user_id int4 not null references Customer (user_id) on update cascade on delete restrict
|
|---|
| 339 | );
|
|---|
| 340 |
|
|---|
| 341 | create table Report
|
|---|
| 342 | (
|
|---|
| 343 | ride_id int4 references Ride (id) on update cascade on delete restrict,
|
|---|
| 344 | customer_user_id int4 references Customer (user_id) on update cascade on delete restrict,
|
|---|
| 345 | message text check ( char_length(message) <= 1000 ),
|
|---|
| 346 | title text check ( char_length(title) <= 1000 ),
|
|---|
| 347 | created_at timestamp not null default current_timestamp,
|
|---|
| 348 | latitude double precision check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 349 | longitude double precision check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 350 | reason text check (char_length(reason) <= 500),
|
|---|
| 351 | primary key (ride_id,
|
|---|
| 352 | customer_user_id)
|
|---|
| 353 | );
|
|---|
| 354 |
|
|---|
| 355 | create table ChatMessage
|
|---|
| 356 | (
|
|---|
| 357 | id serial primary key,
|
|---|
| 358 | message text not null check ( char_length(message) > 0 and char_length(message) < 2000),
|
|---|
| 359 | timestamp timestamp not null default current_timestamp,
|
|---|
| 360 | user_id_from int4 references AppUser (id) on update cascade on delete set null,
|
|---|
| 361 | ride_id int4 references Ride (id) on update cascade on delete set null
|
|---|
| 362 | );
|
|---|
| 363 |
|
|---|
| 364 | create table Location
|
|---|
| 365 | (
|
|---|
| 366 | id serial primary key,
|
|---|
| 367 | latitude double precision not null check ( latitude >= -90 and latitude <= 90 ),
|
|---|
| 368 | longitude double precision not null check ( longitude >= -180 and longitude <= 180 ),
|
|---|
| 369 | timestamp timestamp not null,
|
|---|
| 370 | ride_id int4 references Ride (id) on update cascade on delete set null
|
|---|
| 371 | );
|
|---|
| 372 |
|
|---|
| 373 | create table Payment
|
|---|
| 374 | (
|
|---|
| 375 | id serial primary key,
|
|---|
| 376 | completed_ride_id int4 references Ride (id) on update cascade on delete set null,
|
|---|
| 377 | total_amount numeric(19, 2) not null check ( total_amount > 0 ),
|
|---|
| 378 | currency_catalog_id int4 references CurrencyCatalog (id) on update cascade on delete restrict
|
|---|
| 379 | );
|
|---|
| 380 |
|
|---|
| 381 | create type payment_method_type as enum ('CASH','CARD');
|
|---|
| 382 | create table CustomerPayment
|
|---|
| 383 | (
|
|---|
| 384 | customer_user_id int4 not null default -1 references Customer (user_id) on update cascade on delete set default,
|
|---|
| 385 | payment_id int4 not null default -1 references Payment (id) on update cascade on delete set default,
|
|---|
| 386 | amount numeric(19, 2) not null check ( amount > 0 ),
|
|---|
| 387 | currency_catalog_id int4 not null references CurrencyCatalog (id) on update cascade on delete restrict,
|
|---|
| 388 | timestamp timestamp not null default current_timestamp,
|
|---|
| 389 | payment_method payment_method_type,
|
|---|
| 390 | transaction_id varchar(64) unique,
|
|---|
| 391 | primary key (customer_user_id,
|
|---|
| 392 | payment_id)
|
|---|
| 393 | );
|
|---|
| 394 |
|
|---|
| 395 | create table driver_vehicle
|
|---|
| 396 | (
|
|---|
| 397 | id serial primary key,
|
|---|
| 398 | vin_vehicle varchar(17) not null references vehicle (vin) on delete restrict on update cascade,
|
|---|
| 399 | id_driver int not null references driver (user_id) on delete restrict on update cascade,
|
|---|
| 400 | time_from timestamp not null,
|
|---|
| 401 | time_to timestamp
|
|---|
| 402 | ); |
|---|